//
//  BuildingManagementViewController.swift
//  PropertyCommunity
//
//  Created by benwang on 2021/7/3.
//

import UIKit
import CollectionKit

class BuildingManagementViewController: UIViewController {
  var collectionView = CollectionView()
  var handle = PTSheetHandle()

  override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    opacityNavigationBar(color: .designKit.background)

    view.backgroundColor = .designKit.secondaryBackground
    view.addSubview(collectionView)

    title = "楼栋管理"

    collectionView.snp.makeConstraints { maker in
      maker.edges.equalToSuperview()
    }

    let dataSource = ArrayDataSource<BuildingManagementModel>(
      data: BuildingManagementModel.items
    )

    let viewSource = ClosureViewSource<BuildingManagementModel, UnitImageTextView> { item, data, index in
      item.text = data.name
      item.font = .designKit.bodyBold
    }

    let sizeSource = { (index: Int, data: BuildingManagementModel, size: CGSize) in
      return CGSize(width: (size.width - 10) / 2, height: 80)
    }

    let inset = UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15)

    let itemProvider = BasicProvider<BuildingManagementModel, UnitImageTextView>(
      dataSource: dataSource,
      viewSource: viewSource,
      sizeSource: sizeSource,
      layout: FlowLayout(spacing: 10)
        .inset(by: inset)
    )

    itemProvider.animator = FadeAnimator()
    itemProvider.tapHandler = { (context) in
      self.jump(to: context.data)
    }

    collectionView.provider = ComposedProvider(sections: [itemProvider])
  }

  func jump(to item: BuildingManagementModel) {
    
    handle.sheet(buildingInfo: nil) { index in

    }
  }



  /*
   // MARK: - Navigation

   // In a storyboard-based application, you will often want to do a little preparation before navigation
   override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
   // Get the new view controller using segue.destination.
   // Pass the selected object to the new view controller.
   }
   */

}

struct BuildingManagementModel {
  let name: String
}

extension BuildingManagementModel {
  static let items: [BuildingManagementModel] = (1...6).map {
    .init(name: "\($0)栋")
  }
}
